// ignore_for_file: must_be_immutable

import 'package:flutter/material.dart';
import './category.dart';
import './homePage.dart';
import './setting.dart';
import './mine.dart';

void main() {
  runApp(const MaterialApp(
    home: MyText1(),
  ));
}

class MyText1 extends StatefulWidget {
  const MyText1({super.key});

  @override
  State<MyText1> createState() => _MyText1State();
}

class _MyText1State extends State<MyText1> {
  int selectedIndex = 0;

  List<Widget> renderList = const [
    HomePage(),
    SettingPage(),
    CategoryPage(),
    MinePage()
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('这是title'),
        backgroundColor: Colors.blue,
      ),
      body: renderList[selectedIndex],
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        currentIndex: selectedIndex,
        onTap: (v) {
          if (selectedIndex != v) {
            setState(() {
              selectedIndex = v;
            });
          }
        },
        items: const [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
          BottomNavigationBarItem(icon: Icon(Icons.settings), label: '设置'),
          BottomNavigationBarItem(icon: Icon(Icons.category), label: '菜单'),
          BottomNavigationBarItem(
              icon: Icon(Icons.my_library_add), label: '我的'),
        ],
      ),
    );
  }
}
